<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>打印采购计划单</title>
    <script src="/jquery-1.8.3.min.js"></script>
    <script src="/printThis.js"></script>
    <script src="/chineseMoney.js"></script>
    <script src="/tools.js"></script>
    <link rel="stylesheet" href="/print.css"/>
</head>
<body>
<div id="receiptPrintArea0">
    <h3 style="text-align: center">采购计划单<span class="originalProcess"></span></h3>
    <br/>
    <table width="100%">
        <tr>
            <td width="25%">配货日期范围：</td><td width="75%"><span class="distributionDate"></span></td>
        </tr>
        <tr>
            <td width="25%">食材类型：</td><td width="75%"><span class="type"></span></td>
        </tr>
    </table>
    <br/>
    <table style="width: 100%;" class="printTable">
        <thead style="border: 1px solid">
        <td width="20%">名称</td>
        <td width="15%">规格</td>
        <td width="15%">品牌</td>
        <td width="10%">单位</td>
        <td width="15%">数量</td>
        </thead>
        <tbody id="content">
        </tbody>
    </table>
</div>
<script th:inline="javascript">
    var params = [[${params}]];
    var foodMaterialType = params.foodMaterialType;
    var beginDistributionDate = params.beginDistributionDate;
    var endDistributionDate = params.endDistributionDate;
    var foodMaterialTypeName = params.foodMaterialTypeName;
    var backAddress = params.backAddress;
    var originalProcess = params.originalProcess;
    var kitchen = params.kitchen;
    function print() {
        $("#receiptPrintArea0").printThis({
            debug: false,
            importCSS: true,
            importStyle: true,
            printContainer: true,
            pageTitle: "",
            removeInline: false,
            printDelay: 333,
            header: null,
            formValues: true
        });
    }
    $.ajax({
            url: backAddress + (originalProcess == false ? "/api/purchase/queryPlan" : "/api/purchase/queryProcessPlan"),
            data : JSON.stringify({
                    "beginDistributionDate" : beginDistributionDate,
                    "endDistributionDate" : endDistributionDate,
                    "foodMaterialType" : foodMaterialType,
                    "originalProcess" : originalProcess,
                    "kitchen" : kitchen
            }),
            type: "post",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            //traditional : true,
            success: function (data) {
                //console.log(data)
                $(".distributionDate")[0].innerText = beginDistributionDate + '至' + endDistributionDate;
                $(".type")[0].innerText = foodMaterialTypeName;
                $(".originalProcess")[0].innerText = getOriginalProcess(originalProcess);
                var str = '' ;
                console.log(data.data)
                for (var i = 0 ; i < data.data.length ; i++) {
                    str = "<tr><td width=\"20%\">" + data.data[i].foodMaterialName + "</td>" +
                        "<td width=\"15%\">" + dealNull(data.data[i].specs) + "</td>" +
                        "<td width=\"15%\">" + dealNull(data.data[i].brand) + "</td>" +
                        "<td width=\"10%\">" + dealNull(data.data[i].unitName) + "</td>" +
                        "<td width=\"15%\">" + data.data[i].planAmount + "</td></tr>" ;
                    $("#content").append($(str));
                }
                print()
            },
            error: function (status) {
                alert(status)
            }
        }
    )
</script>
</body>
</html>